package cn.gjxblog.service.impl;

import cn.gjxblog.dao.BlogMapper;
import cn.gjxblog.model.entity.Blog;
import cn.gjxblog.model.entity.BlogExample;
import cn.gjxblog.service.BlogServcie;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 作用:
 * 作者:gjx
 * 版本:V1.0
 * 创建时间: 2019/1/19 17:56
 */
@Service
public class BlogServiceImpl implements BlogServcie {

    @Resource
    private BlogMapper blogMapper;

    @Override
    public PageInfo<Blog> queryBlog(Blog blog, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        BlogExample blogExample = new BlogExample();
        if(StringUtils.isNotBlank(blog.getTags())){
            blogExample.createCriteria().andTagsLike("%"+blog.getTags()+"%");
        }
        List<Blog> blogs = blogMapper.selectByExampleWithBLOBs(blogExample);
        PageInfo<Blog> pageInfo = new PageInfo<>(blogs);
        return pageInfo;
    }



    @Override
    public Blog getBlog(String id) {
        Blog blog = blogMapper.selectByPrimaryKey(id);
        return blog;
    }
}
